<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script type="text/javascript">
        // ES5 初始化参数 默认值：undefined
        function test(a, b) {
            // 1. 参数默认值
            // a = arguments[0] || 1;
            // b = arguments[1] || 2;
            // 2. 参数默认值
            a = typeof (arguments[0]) !== "undefined" ? arguments[0] : 1;
            b = typeof (arguments[1]) !== "undefined" ? arguments[1] : 2;
            console.log(a + b);
        }
        test();
        // ES6 初始化参数 默认值：undefined
        function test1(a, b=5) {
            return a*b;
        }
        console.log(test1(2));

        // 阶乘 递归
        // 5*4*3*2*1
        function factorial(n) {
            return n==1?1: n * factorial(--n);
        }
        console.log(factorial(5));
        // 阶乘 循环
        function factorial1(n){
            for(let i = n - 1;i>0;i--){ 
                n*=i;
            }
            return n;
        }
        console.log(factorial1(5));;
    </script>
</body>

</html>